package com.itheima.service.impl;

import com.itheima.mapper.CheckItemMapper;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;


    @Override
    public Map<String, Object> selectfindPage(Integer currentPage, Integer pageSize, String queryString) {
        Integer start = (currentPage - 1) * pageSize;
        if (queryString != null && queryString.length() > 0){
            queryString = "%" + queryString + "%";
        }
        Long total = checkItemMapper.queryTotal(start, pageSize, queryString);
        List<CheckItem> checkItemList = checkItemMapper.selectfindPage(start, pageSize, queryString);
        Map<String, Object> map = new HashMap<>();
        map.put("total",total);
        map.put("rows",checkItemList);
        return map;
    }






    @Override
    public void add(CheckItem checkItem) {
        checkItemMapper.add(checkItem);
    }

    @Override
    public void delete(Integer id) throws RuntimeException {
        checkItemMapper.deleteById(id);
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkItemMapper.findById(id);
    }

    @Override
    public void edit(CheckItem checkItem) {
        checkItemMapper.edit(checkItem);
    }
}
